<?xml version="1.0"?>
<!--
This file is part of the Foothill College Web GIS.

Foothill College Web GIS is free software: you can redistribute it 
and/or modify it under the terms of the GNU General Public License 
as published by the Free Software Foundation, either version 3 of 
the License, or (at your option) any later version.

Foothill College Web GIS is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with Foothill College Web GIS. If not, see 
<http://www.gnu.org/licenses/>.
-->

<!-- run the generated kml through this to add
     id attributes to each placemark. If the KML format
     changes, you'll need to mess with the XPath expression in 
     xsl:attribute 
     cammand: xslt -o geocode.kml geocode.xsl src.kml -->

<xsl:stylesheet version="1.0"
		xmlns:xsl="http://www.w3.org/1999/XSL/Transform"
		xmlns:kml="http://www.opengis.net/kml/2.2">

  <xsl:output method="xml" indent="no" omit-xml-declaration="no" encoding="utf-8"/>


  <!-- everything (except what we modify below) should be unmodified -->
  <xsl:template match="*">
    <xsl:copy>
      <xsl:copy-of select="@*" />
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>

  <!-- delete unnecessary stuff to minimize file size -->
  <!-- don't care about gid -->
  <xsl:template match="kml:SimpleData[@name='gid']" />
  <xsl:template match="kml:SimpleField[@name='gid']" />

  <!-- Select every Placemark and transform it -->
  <xsl:template match="kml:Placemark">
    <!-- Copy it... -->
    <xsl:copy>
      <!-- but add the atribute -->
      <xsl:attribute name="id"><xsl:value-of select="./kml:ExtendedData/kml:SchemaData/kml:SimpleData[@name='room_no']" /></xsl:attribute>
      <xsl:copy-of select="@*" />
      <xsl:apply-templates />
    </xsl:copy>
  </xsl:template>

</xsl:stylesheet>